<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/10/19 0019
 * Time: 10:47
 */
//文章表
namespace Api\Controller;
use Think\Controller;

class ArticleColumnController extends Controller
{

    public function article()
    {
        $article_column = M('article_column')->where('state=1')->select();

        foreach ($article_column as $k=>$v){
            $article_column[$k]['list'] = M('article_list')->where('state=1 and column_id='.$v['column_id'])->order('release_time desc')->limit(4)->select();
            foreach ($article_column[$k]['list'] as $kk => $vv){
                $pattern = "/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png]))[\'|\"].*?[\/]?>/";
                preg_match_all($pattern, $article_column[$k]['list'][$kk]['article_text'], $match);
                $img = $match[1][0];
                $article_column[$k]['list'][$kk]['img'] =$img == '' ? 'http://img1.cache.netease.com/cnews/css13/img/end_news.png': $img;
                $article_column[$k]['list'][$kk]['release_time'] = date("Y-m-d",strtotime($vv['release_time']));
                $text = str_replace(array("\r\n", "\r", "\n"," "), '', strip_tags($article_column[$k]['list'][$kk]['article_text']));
                $article_column[$k]['list'][$kk]['article_text'] = mb_substr($text,0,50,'utf-8').(mb_strlen($text,'UTF8')>50?"......":"");
            }
        }
        $this->ajaxReturn($article_column,'JSON');
    }
}